package cn.northsea.service.impl;

//业务层要按照接口和实现类的方式编写

import cn.northsea.mapper.RoleMapper;
import cn.northsea.pojo.Role;
import cn.northsea.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> findAll(String likename) {
        return roleMapper.findAll(likename);
    }

    @Override
    public void addRole(Role role) {
        role.setCreateAt(new Date(System.currentTimeMillis()));
        roleMapper.addRole(role);
    }

    @Override
    public Role checkRoleName(String roleName) {
        return roleMapper.checkRoleName(roleName);
    }

    @Override
    public void delRole2(Integer[] ids) {
        roleMapper.delRole2(ids);
    }

    @Override
    public List<Role> findRoleByUid(Integer id) {
        return roleMapper.findRoleByUid(id);
    }

    @Override
    public List<Role> findAll2() {
        return roleMapper.findAll2();
    }

    @Override
    @Transactional
    public void allocationRole(Integer userId, List<Integer> rids) {
        roleMapper.delRole(userId);
        roleMapper.allocationRole(rids, userId);
    }

}
